#pragma once

#include <iostream>
#include <cassert>
#include "basetypes.h"

/*
 *	Binary-Coded Decimal
 *	Author: Filippo Fantini
 *	Date: 17/3/2010
 *	Description:
 *		A really big number!
 *		Each deciamal digit is stored with 1 byte (could be stored with 1 nibble...)
*/
namespace ZioUtils
{
	class bcd
	{
		friend std::ostream& operator<<(std::ostream& out, const bcd& number);	// Print the number to the std out
	public:
		bcd(const char* const number_string);									// Conversion Constructor from a string
		bcd(const UInt64 number = 0);											// Conversion Constructor from a number (uga: it's better to provide an empty ctor)
		bcd(const bcd& copy);													// Copy Constructor
		~bcd();																	// Destructor

		// Operators
		bcd&			operator=	(const bcd& other);								// Assignment
		bcd&			operator+=	(const bcd& other);								// Addition
		bcd				operator+	(const bcd& other);
		bcd&			operator*=	(const bcd& other);

		// Get Methods
		UInt32			NumberOfDigits() const;									// Number of digits
		UInt8			GetDigit(const UInt32 i) const;							// Returns the i th digit 
		UInt64			GetValue() const;										// Try to convert to a number

	private:
		void			AllocMemory(UInt32 size);								// Utility function to realloc memory
		void			ResizeMemory(UInt32 size);								// Resize

		UInt8*			m_data;													// Numbers data
		UInt32			m_length;												// 10^(2^32) digits should be enough...
	};
}
